package com.dwms.controller;

import com.dwms.entity.PageResponse;
import com.dwms.entity.QueryRequest;
import com.dwms.entity.Result;
import com.dwms.entity.base.sellerKey.request.SellerKeyQueryRequest;
import com.dwms.entity.base.sellerKey.request.SellerKeyRequest;
import com.dwms.entity.base.sellerKey.response.SellerKeyResponse;
import com.dwms.feign.seller.SellerKeyFeignClient;
import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: SellerKeyController
 * @Description: SellerKey
 * @Create 2025-08-27 14:40:51
 * @Author WH
 * @Since 1.0.0
**/
@Tag(name = "商家密钥管理")
@RestController
@RequestMapping(value = "/seller/key")
@RequiredArgsConstructor
public class SellerKeyController {

    private final HttpServletRequest request;
    private final SellerKeyFeignClient sellerKeyFeignClient;

    /**
     * 保存
     *
     * @param sellerKeyRequest
     *          请求参数
     * @return
     */
    @Operation(summary = "新增密钥")
    @PostMapping("/save")
    public Result save(@RequestBody SellerKeyRequest sellerKeyRequest) {
        WebUtil.getAdminRequest(request, sellerKeyRequest);
        return sellerKeyFeignClient.save(sellerKeyRequest);
    }

    /**
     * 修改
     *
     * @param sellerKeyRequest
     *          请求参数
     * @return
     */
    @Operation(summary = "修改密钥")
    @PostMapping("/update")
    public Result update(@RequestBody SellerKeyRequest sellerKeyRequest) {
        WebUtil.getAdminRequest(request, sellerKeyRequest);
        return sellerKeyFeignClient.update(sellerKeyRequest);
    }
    

    /**
     * 分页查询
     *
     * @param query
     *          查询参数
     * @return
     */
    @Operation(summary = "分页查询")
    @PostMapping("/findPage")
    public Result<PageResponse<SellerKeyResponse>> findPage(@RequestBody SellerKeyQueryRequest query) {
        WebUtil.getAdminRequest(request, query);
        return sellerKeyFeignClient.findPage(query);

    }

    /**
     *  根据ID查询
     *
     * @param query
     *          参数
     * @return
     */
    @Operation(summary = "根据ID查询")
    @PostMapping("/findById")
    public Result findById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request, query);
        return this.sellerKeyFeignClient.findById(query);
    }

    /**
     * 删除
     *
     * @param query
     *          ID
     * @return
     */
    @Operation(summary = "删除密钥")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request, query);
        return this.sellerKeyFeignClient.delete(query);
    }

}
